<?php

namespace app\adminapi\controller;
// 添加这句，注释写法为 @Apidoc\参数名(...)
use app\exceptions\AdminException;
use app\exceptions\AuthException;
use app\services\setting\admin\SystemAdminService;
use hg\apidoc\annotation as Apidoc;
use app\BaseController;
use PhpOffice\PhpSpreadsheet\Reader\Xls\MD5;
use tauthz\facade\Enforcer;
use think\facade\App;
use think\Request;


/**
 * https://hgthecode.github.io/thinkphp-apidoc/use/notes/api/#%E5%9F%BA%E7%A1%80%E6%B3%A8%E9%87%8A 文档地址
 * @Apidoc\Title("登录管理")
 * @Apidoc\Group("login")
 */
class Login extends AuthController

{
    public function __construct(App $app, SystemAdminService $service)
    {
        parent::__construct($app);
        $this->services = $service;
    }

    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
    }


    /**
     * 获取首页信息
     * @Apidoc\Title("基础的注释方法")
     * @Apidoc\Desc("最基础的接口注释写法")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("Ambition")
     * @Apidoc\Tag("测试")
     * @Apidoc\Param("username", type="abc",require=true, desc="用户名")
     * @Apidoc\Param("password", type="string",require=true, desc="密码")
     * @Apidoc\Param("phone", type="string",require=true, desc="手机号")
     * @Apidoc\Param("sex", type="int",default="1",desc="性别" )
     */
    public function index()
    {

        $where = $this->request->postMore([
            ['website_id', $this -> website],
        ]);
        return app()->make('json')->successful( $this->services->indexData($where));
    }

    /**
     * 登录接口
     * @return void
     */
    public function login()
    {


        $where = $this->request->postMore([
            ['userName', ''],
            ['password', ''],
        ]);
        return app()->make('json')->successful($this->services->login($where));

    }

    /**
     * 获取用户信息
     * @return void
     */
    public function info()
    {
        $where = $this->request->postMore([
            ['accessToken', ''],
        ]);
        if (!$where['accessToken']) throw  new AuthException('accessToken不存在！', 402);
        return app()->make('json')->successful($this->services->info($where));

    }


}